<?php

namespace App\Http\Controllers\Admin;

use App\admin\Adlog;
use App\admin\About;
use App\Http\Controllers\Admin\LogHander;
use App\Http\Controllers\Controller;
use App\Http\Middleware;
use Illuminate\Http\Request;
use Intervention\Image\ImageManagerStatic as Image;
use Illuminate\Routing\Controller as BaseController;

class AboutUsController extends BaseController
{
	public function __construct() {
		$this->middleware('admindo');
	}
	public function index(Request $request)
	{
		$id = $request->input('id');
		$About = new About;
		$data = $About::find($id);
		if(empty($data)){
			return "没有此数据";
		}else{
			return view('admin.aboutdetial',['data' => $data]);
		}
	}
	
//	public function list(Request $request){
//		$flight = About::where('state',0)->orderBy('id', 'desc')->paginate(15);
//		return view('admin.aboutlist',['data' => $flight]);
//	}
//	
//	public function del(Request $request){
//		
//	}
	
	public function edite(Request $request){
		$id = $request->input('id');
		$Newnet = new About;
		$data = $Newnet::find($id);
		if(empty($Newnet)){
			return "没有此数据";
		}else{
			return view('admin.aboutedite',['data' => $data]);
		}
	}
	
	public function editeUp(Request $request){
		$id = $request->input('id');
		if($id == ""){
			return "找不到id";
		}
		$Newnet = new About;
		$newName = $request->input('newName');
		$newAuthor = $request->input('newAuthor');
		$newFrom = $request->input('newFrom');
		$Description = $request->input('newDescription');
		$content = $request->input('content');
		$pathBase = "";
		
		if ($request -> hasFile('fileOne')) {
			$file = $request -> file('fileOne');
			$entension = $file -> getClientOriginalExtension();
			$ents = array("jpg", "jpge", "png", "bmp","gif");
			if(!in_array($entension, $ents)){
				return "只支持jpg, jpge, png, bmp,gif类型的图片";
			}
			$name = date("Ymd").str_random(10) . '.'.$entension;
			$path = public_path() .'/upload/about/'. $name;
			Image::make($file) -> save($path);
			$pathBase = 'upload/about/'. $name;
		}
		
		$temp = $Newnet::find($id);
		$temp->name = $newName;
		$temp->description = $Description;
		$temp->author = $newAuthor;
		$temp->froms = $newFrom;
		$temp->info = $content;
		if($pathBase != ""){
			$temp->imgurl = $pathBase;
		}
		$temp->state = 0;
		if($temp->save()){
			$cars=array('name'=>'editeUp','info'=>'编辑关于我 们','users'=>'更新了id='.$id.'的内容','cnt'=>$newName);
			$tempx = new LogHander;
			$tempx->logs($cars);
			return redirect('aboutedite'."?id=".$id);
		}else{
			return "更新失败";
		}
	}
}
